package util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 解析配置文件工具类
 */
public class ConfigManager {
    static ConfigManager configManager;
    Properties properties;
    private ConfigManager(){
        properties = new Properties();
        InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream("database.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //单例模式  懒汉   先创建后赋对象
    public static ConfigManager getInstance(){
        if(configManager==null){
            configManager = new ConfigManager();
        }
        return configManager;
    }
    //通过key访问value
    public String getValue(String key){
        return properties.getProperty(key);
    }
}
